package com.powergame.model;

/**
 * TypePiece.java
 *
 * Spécificités d'une pièce
 *
 * @author ToF
 */
public class TypePiece {

    // Constantes à utiliser
    public static final TypePiece PIECE_SOLDAT = new TypePiece(1, "Soldat", 2, 2);
    public static final TypePiece PIECE_TANK = new TypePiece(2, "Tank", 3, 3);
    public static final TypePiece PIECE_CHASSEUR = new TypePiece(3, "Chasseur", 5, 5, true, false);
    public static final TypePiece PIECE_DESTROYER = new TypePiece(4, "Destroyer", 1, 10, false, true);
    public static final TypePiece PIECE_REGIMENT = new TypePiece(5, "Régiment", 2, 20);
    public static final TypePiece PIECE_CHAR = new TypePiece(6, "Char d'assault", 3, 30);
    public static final TypePiece PIECE_BOMBARDIER = new TypePiece(7, "Bombardier", 5, 25, true, false);
    public static final TypePiece PIECE_CROISEUR = new TypePiece(8, "Croiseur", 1, 50, false, true);
    public static final TypePiece PIECE_MEGA_MISSILE = new TypePiece(9, "Mega-missile", 999, 100, true, true);

    public static TypePiece parseTypePiece(String str) {
        if(str.equalsIgnoreCase("soldat")){
            return PIECE_SOLDAT;
        }else if(str.equalsIgnoreCase("tank")){
            return PIECE_TANK;
        }else if(str.equalsIgnoreCase("chasseur")){
            return PIECE_CHASSEUR;
        }else if(str.equalsIgnoreCase("destroyer")){
            return PIECE_DESTROYER;
        }else if(str.equalsIgnoreCase("regiment")){
            return PIECE_REGIMENT;
        }else if(str.equalsIgnoreCase("char")){
            return PIECE_CHAR;
        }else if(str.equalsIgnoreCase("bombardier")){
            return PIECE_BOMBARDIER;
        }else if(str.equalsIgnoreCase("croiseur")){
            return PIECE_CROISEUR;
        }else if(str.equalsIgnoreCase("mega")){
            return PIECE_MEGA_MISSILE;
        }else{
            return null;
        }
    }
    
    /** Identifiant unique */
    private int id = 0;
    
    /** Le libellé pour les affichages et debug */
    private String libelle = null;
    
    /** Indique la pièce peut traverser les océans */
    private boolean aerienne = false;
    
    /** Indique si la pièce peut aller dans les terres */
    private boolean navale = false;
    
    /** Déplacement maxi */
    private int deplacement = 0;
    
    /** Valeur/Puissance */
    private int power = 0;
    
    public TypePiece(int id, String libelle, int deplacement, int power){
        this.id = id;
        this.libelle = libelle;
        this.deplacement = deplacement;
        this.power = power;
    }
    
    public TypePiece(int id, String libelle, int deplacement, int power, boolean aerienne, boolean navale){
        this.id = id;
        this.libelle = libelle;
        this.aerienne = aerienne;
        this.deplacement = deplacement;
        this.power = power;
        this.navale = navale;
    }

    public boolean isAerienne() {
        return aerienne;
    }

    public void setAerienne(boolean aerienne) {
        this.aerienne = aerienne;
    }

    public boolean isNavale() {
        return navale;
    }

    public void setNavale(boolean navale) {
        this.navale = navale;
    }
    
    public int getDeplacement() {
        return deplacement;
    }

    public void setDeplacement(int deplacement) {
        this.deplacement = deplacement;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLibelle() {
        return libelle;
    }

    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }

    public int getPower() {
        return power;
    }

    public void setPower(int power) {
        this.power = power;
    }

    boolean traverse(TypeSecteur type) {
        if(type.equals(TypeSecteur.SECTEUR_MER)){
            return isNavale();
            
        }else if(type.equals(TypeSecteur.SECTEUR_TERRE)){
            return !isNavale();
            
        }else{
            return true;
        }
    }
}
